package com.situ.cloud.gateway.conf;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

import java.util.ArrayList;
import java.util.List;


@Configuration
@EnableWebFluxSecurity
public class SecurityConfig {

    private List<String> blackListPath = new ArrayList<>();

    @Bean
    public SecurityWebFilterChain webSecurityConfigurer(ServerHttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .authorizeExchange(exchange ->
                {
                    if (CollectionUtil.isNotEmpty(blackListPath)) {
                        exchange.pathMatchers(Convert.toStrArray(blackListPath)).authenticated();
                    }
                    exchange.anyExchange().permitAll();
                })
                .csrf().disable();
        return httpSecurity.build();
    }

}
